"""
Case Type   : objects
Case Name   : 重建当前数据库上所有系统表上的索引
Create At   : 2023/8/2
Owner       : @li-xin12345
Description :
    1、重建当前数据库上所有系统表上的索引
Expect      :
    1、成功
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger


class TestObject(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_sh = CommonSH('PrimaryDbUser')

    def test_object(self):
        text = '-----step1:重建当前数据库上所有系统表上的索引;expect:成功-----'
        self.log.info(text)
        sql = 'select current_database();'
        res = self.pri_sh.execut_db_sql(sql)
        self.log.info(res)
        self.assertIn('1 row', res, '执行失败:' + text)

        db_name = res.splitlines()[-2].strip()
        sql = f'reindex system {db_name};'
        res = self.pri_sh.execut_db_sql(sql)
        self.log.info(res)
        self.assertIn('REINDEX', res, '执行失败:' + text)

    def tearDown(self):
        text = '-----无需清理环境-----'
        self.log.info(text)
        self.log.info(f'-----{os.path.basename(__file__)} end-----')